package czk.concrent.createthread.practice;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * FutureTask的任务创建
 *
 * @Author:ChenZhangKun
 * @Date: 2021/7/7 10:14
 */
public class FutureTaskPractice {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建任务
        FutureTask futureTask = new FutureTask(() -> {
            Thread.sleep(5000);
            return 2;
        });
        // 创建任务
        Thread thread = new Thread(futureTask);
        // 启动线程
        thread.start();
        // 拿到结果，此时要阻塞
        Object o = futureTask.get();
        System.out.println(o);
    }
}
